<?php

/**
* 接口基础抽象类
*/
abstract class openapi_api_function_base
{
	
	function __construct()
	{
		# code...
	}

	/**
     * @param $flag - 请求状态 true:成功false:失败
     * @param $data - 需要返回的数据或提示信息
     * @return mixed
     * @author 张学会 <phlv@163.com>
     */
    public function apiData($flag,$data,$code,$msg)
    {
        $this->addslashes_fb($data);
        if ($flag) {
            $res['status'] = 'success';
            $res['data'] = $data;
        }else{
            $res['status'] = 'error';
            $res['data'] = $data;
        }
        $res['code'] = $code;
        $res['msg'] = $msg;
        return $res;
    }

    function addslashes_fb(&$aData)
    {
        if(is_array($aData)){
            foreach ($aData as $k => &$ad) {
                $this->addslashes_fb($ad);
            }
        }
        if(is_string($aData)){
            $aData = addslashes($aData);
        }
    }

    /**
    * loginlimit-登陆受限检测
    *
    * @param      none
    * @return     void
    */
    function loginlimit($mid,&$redirect) {
        $services = kernel::servicelist('loginlimit.check');
        if ($services){
            foreach ($services as $service){
                $redirect = $service->checklogin($mid);
            }
        }
        return $redirect?true:false;
    }

}